﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZK.BLL;

namespace ZK.Client.WinForm
{
    public partial class FrmCustomerSelect : Form
    {
        public FrmCustomerSelect()
        {
            InitializeComponent();
        }

        public string Selected { get; set; }
        private void btnQuery_Click(object sender, EventArgs e)
        {

            string[] customers = ProductInfoBLL.Instance.GetList().Select(s => s.CustomerName).Distinct().ToArray();

            lbCustomer.Items.Clear();

            foreach (var cc in customers.ToList().FindAll(s=> s.Contains(txtQuery.Text.Trim())))
            {
                lbCustomer.Items.Add(cc);
            }
        }

        private void FrmCustomerSelect_Load(object sender, EventArgs e)
        {
            string[] customers = ProductInfoBLL.Instance.GetList().Select(s => s.CustomerName).Distinct().ToArray();

            lbCustomer.Items.Clear();

            foreach (var cc in customers)
            {
                lbCustomer.Items.Add(cc);
            }

        }

     
        private void btnSure_Click(object sender, EventArgs e)
        {
            if (lbCustomer.SelectedItems.Count > 0)
            {
                Selected = lbCustomer.SelectedItems[0].ToString();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
